package org.obs.core.hibernate.operations;

import org.hibernate.Query;
import org.hibernate.Session;
import org.obs.core.HibernateOperation;

public class GetUserIdByEmailOperation implements HibernateOperation <Long> {

	private String email;

	public GetUserIdByEmailOperation(String email) {
		this.email = email;
	}

	private static final String queryString = "select u.id from User as u where u.email = :email"; 
	
	public Long execute(Session session) {
		Query query = session.createQuery(queryString);
		query.setParameter("email", email);
		return (Long) query.uniqueResult();
	}

}
